package formal.queueStack;

import java.util.LinkedList;
import java.util.Queue;

/**
 * 用队列实现栈
 * @author DengYuan2
 * @create 2021-01-27 22:16
 */
public class E_225 {
    public class MyStack{
        Queue<Integer> queue = new LinkedList<>();
        public void push(int x){
            queue.add(x);
            int cnt = queue.size();
            while (cnt-- >0){
                queue.add(queue.poll());
            }
        }

        public int pop(){
            return queue.remove();
        }

        public int top(){
            return queue.peek();
        }

        public boolean empty(){
            return queue.isEmpty();
        }
    }
}
